package com.aaa.controller;

import com.aaa.aspect.InsertAnn;
import com.aaa.aspect.UpdateAnn;
import com.aaa.entity.MyReturn;
import com.aaa.entity.TestPlanFpa;
import com.aaa.service.TestPlanFpaService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * 测试计划fpa(TestPlanFpa)表控制层
 *
 * @author
 * @since 2022-07-08 09:59:06
 */
@RestController
@RequestMapping("testPlanFpa")
public class TestPlanFpaController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private TestPlanFpaService testPlanFpaService;
    MyReturn myReturn = new MyReturn();

    @RequestMapping("toShowTestPlanFpa.do")
    public ModelAndView toShowTestPlanFpa(ModelAndView modelAndView) {
        modelAndView.setViewName("showTestPlanFpa");
        return modelAndView;
    }

    /**
     * 分页查询
     *
     * @param testPlanFpa 筛选条件
     * @return 查询结果
     */
    @RequestMapping("queryByPage.do")
    public ResponseEntity<Page<TestPlanFpa>> queryByPage(TestPlanFpa testPlanFpa, Integer page, Integer limit) {
        PageRequest pageRequest = PageRequest.of(page - 1, limit);
        return ResponseEntity.ok(this.testPlanFpaService.queryByPage(testPlanFpa, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<TestPlanFpa> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.testPlanFpaService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param testPlanFpa 实体
     * @return 新增结果
     */
    @PostMapping("insertPlan.do")
    @InsertAnn
    public MyReturn add(TestPlanFpa testPlanFpa) {
        boolean insert = this.testPlanFpaService.insert(testPlanFpa);
        if (insert) {
            return getSuccessResult(myReturn);
        }
        return getFailResult(myReturn);
    }

    /**
     * 编辑数据
     *
     * @param testPlanFpa 实体
     * @return 编辑结果
     */
    @RequestMapping("updatePlanFpa.do")
    @UpdateAnn
    public MyReturn edit(TestPlanFpa testPlanFpa) {
        boolean update = this.testPlanFpaService.update(testPlanFpa);
        if (update) {
            return getSuccessResult(myReturn);
        }
        return getFailResult(myReturn);
    }

    /**
     * 删除数据
     *
     * @param idList 主键
     * @return 删除是否成功
     */
    @RequestMapping("deletePlanFpa.do")
    public MyReturn deleteById(String idList) {
        boolean b = this.testPlanFpaService.deleteById(idList);
        if (b) {
            return getSuccessResult(myReturn);
        }
        return getFailResult(myReturn);
    }

    /**
     * @param testPlanFpa
     * @return MyReturn
     * @create by: feng (zhaixing@163.com)
     * @description: 题目唯一性校验
     * @create time: 2022/7/15 15:05
     */
    @RequestMapping("repetitionName.do")
    public MyReturn repetitionName(TestPlanFpa testPlanFpa) {
        boolean b = this.testPlanFpaService.repetitionName(testPlanFpa);
        if (b) {
            return getSuccessResult(myReturn);
        }
        return getFailResult(myReturn);
    }
}

